#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int  N = 1010;
int n , m ;
int w[N] , v[N];
int dp[N];

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1 ; i <= n ; ++i) scanf("%d%d", &v[i], &w[i]);
    
    for(int i =1 ; i <= n ; ++i){
        for(int j = v[i] ; j <= m ; ++j){
                dp[j] = max(dp[j] , dp[j - v[i]] + w[i]);
        }
    }
    printf("%d\n" , dp[m]);
    return 0;
}